/**
 * Created by simontao on 16-8-23.
 */
'use strict';

import AV from "leancloud-storage";

const appId = 'o7gkcpWvDsEywOvDS6G0QwTf-gzGzoHsz';
const appKey = 'hAsx98AMiq2d6B3yRbeeFhky';

AV.init({
  appId,
  appKey
  // 启用美国节点
  // region: 'us',
});


class RemoteObject{
  constructor(tableName){
    this.tableName = tableName;
  }

  getTableName(){
    return this.tableName;
  }

  getOneObject(id) {
    let query = new AV.Query(this.getTableName());
    return query.get(id);
  }

  destoryOneObject(id) {
    return getUserById(id).then(function(user){
      return user.destroy();
    }, function(error){
      console.log(error);
    });
  }

  findOnePageObjects(condition){
    let query = new AV.Query(this.getTableName());
    query.limit(condition.limit);
    query.skip(condition.skip);
    query.descending(condition.descending);
    return query.find();
  }

  //关于user这个特殊表的方法
  userLogIn(userData) {
    return AV.User.logIn(userData.username, userData.password);
  }
  userLogOut(){
    return AV.User.logOut();
  }
  userRegister() {
    var user = new AV.User();
    user.set(userData);
    return user.signUp();
  }
  currentUser() {
    let user = AV.User.current();
    return user;
  }

}

export default RemoteObject;
